#ifndef __MESSAGE_SERVICE_H__
#define __MESSAGE_SERVICE_H__

#include <vector>
#include <map>
#include "fwDefine.h"

struct  Subscriber
{
	char * Tag;
	FWobject Reciever;
	void(*RecallFunc)(const FWobject sender, FWobject extra);
};

struct Publisher
{
	char * Tag;
	FWobject Sender;
	FWobject Extra;
};

class MessageService
{
public:

private:
	std::vector<Subscriber> m_lstSubscribers;
	int m_iCount;
private:
	static MessageService * m_pInstance;
	MessageService();
	void Process(Publisher publisher);
public:
	~MessageService();
	static MessageService * GetInstance();
	static void DestroyInstance();

	void Alloc();
	void Clear();

	void RegisterMessage(const FWobject reciever, char * tag, void(*recallFunc)(const FWobject sender, FWobject extra));
	void SendMessageTag(const FWobject sender, char * tag, FWobject extra);
};

class TagControll
{
private:
	struct _Subscriber
	{
		FWobject Reciever;
		void(*CallBack)(const FWobject sender, FWobject extra);
	};
	struct _Publisher
	{
		FWuint Tag;
		FWobject Sender;
		FWobject Extra;
	};
private:
	std::map<FWuint, std::vector<_Subscriber>> m_lstSubscribers;
public:
	static TagControll* Instance;
private:
	TagControll();
	~TagControll();

	void ExecuteTag(_Publisher);
public:
	static void Alloc();
	static void Malloc();
	void Clear();

	void RegisterTag(FWobject reciever, FWuint tag, void (*callBack)(const FWobject, FWobject));
	void SendTag(const FWobject sender, FWuint tag, FWobject extra);
};

#endif